#!/bin/bash
set -e
SDK_TYPE=$1
myhome="/home/myhome"

RED='\033[0;31m'
NC='\033[0m' # No Color
GREEN='\033[0;32m'
YELLOW='\033[0;33m'

case $SDK_TYPE in
    "openwrt")
        echo -e "${YELLOW}Entry OpenWrt SDK ${NC}"
        ;;
    "lede")
        echo -e "${YELLOW}Entry LEDE SDK ${NC}"
        ;;
    *)
	echo -e "${RED}Must be 'openwrt' or 'lede'...${NC}"
        exit 1
        ;;
esac

# update and install feeds
echo -e "${YELLOW}update and install feeds${NC}"
cd $SDK_TYPE
./scripts/feeds update -a
./scripts/feeds install -a

# copy build_config 
echo -e "${YELLOW}copy build_config${NC}"
[ ! -L build_config ] && {
    ln -s ../build_config/ .
}

[ ! -L build_firmware.sh ] && {
    ln -s ../build_config/build_firmware.sh .
}

# copy custom feeds
echo -e "${YELLOW}copy custom feeds${NC}"
cp -rf ../wifibase-packages/feeds/* feeds/

# link wifibase packages
echo -e "${YELLOW}link wifibase packages${NC}"
[ ! -L package/wifibase-packages ] &&{
	ln -s ../../wifibase-packages package/wifibase-packages
}

# link dl
echo -e "${YELLOW}link dl${NC}"
[ ! -L dl ] && {
    ln -s ../dl .
}

cd $myhome

# create wallfacer buildroot env
echo -e "${YELLOW}create wallfacer buildroot env${NC}"
rm -rf wallfacer
mkdir wallfacer

cd wallfacer
ln -s ../$SDK_TYPE/* .
ln -s ../build_config/.wallfacer_config .config
cd ..

# create wallbreaker buildroot env
echo -e "${YELLOW}create wallbreaker buildroot env${NC}"
rm -rf wallbreaker
mkdir wallbreaker

cd wallbreaker
ln -s ../$SDK_TYPE/* .
ln -s ../build_config/.wallbreaker_config .config
cd ..


echo -e "${GREEN}Init $SDK_TYPE success! ${NC}"
